<template>
  <user-card-list :user-list="userList" />
  <van-empty v-if="!userList || userList.length < 1" description="搜索结果为空" />

<!--    <van-card-->
<!--        v-for="user in userList"-->
<!--        :desc="user.profile"-->
<!--        :title="`${user.username}（${user.planetCode}）`"-->
<!--        :thumb="user.avatarUrl"-->
<!--    >-->
<!--      <template #tags>-->
<!--        <van-tag plain type="danger" v-for="tag in user.tags" style="margin-right: 8px; margin-top: 8px">-->
<!--          {{ tag }}-->
<!--        </van-tag>-->
<!--      </template>-->
<!--      <template #footer>-->
<!--        <van-button size="mini">联系我</van-button>-->
<!--      </template>-->
<!--    </van-card>-->

<!--  <van-empty v-if="!userList || userList.length < 1" description="搜索结果为空" />-->


</template>

<script setup >
import {useRoute} from "vue-router";
const route = useRoute();
import {onMounted, ref} from 'vue';
import myAxios from "../plugins/myAxios.ts";
import {showFailToast, Toast} from "vant";
const { tags } = route.query;
import qs from 'qs';
import UserCardList from "../components/UserCardList.vue";

const userList = ref([]);

onMounted(async () => {
  const userListData = await myAxios.get('/user/search/tags', {
  // myAxios.get('/user/search/tags', {
    params: {
      tagNameList: tags
    },
    paramsSerializer: params => {         //序列化参数
      return qs.stringify(params, {indices: false})
    }
  })
      .then(function (response) {
    console.log('/user/search/tags succeed', response);
    return response?.data;
  })
      .catch(function (error) {
        console.error('/user/search/tags error', error);
        showFailToast('请求失败');
      })
  if (userListData){
    userListData.forEach(user => {
      if (user.tags) {
        user.tags = JSON.parse(user.tags);
      }
    })
    userList.value = userListData;
  }
})

const mockUser = {
  id: 12345,
  username: '紫薯芋泥',
  userAccount: 'zsyn',
  profile: '精神状态堪忧的小女孩一枚.....',
  avatarUrl: 'https://profile-avatar.csdnimg.cn/5e392e4f1ad04d588624f346ddd3dc57_m0_68516464.jpg!1',
  gender: 0,
  phone: '13113113111',
  email: '592342843721987@xzcxzczxcz.com',
  userRole: 0,
  planetCode: '1234',
  tags: ['java', 'emo', '打工中', 'emo', '打工中'],
  createTime: new Date(),
}



</script>

<style scoped>

</style>
